<ui:composition template="/admin/templates/ui2.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:composite="http://java.sun.com/jsf/composite/primefaces"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:sec="http://www.springframework.org/security/facelets/tags">

	<ui:define name="content">
		<div class="entry">
			<p:toolbar>
				<p:toolbarGroup>
					<h:outputLabel style="padding-left: 15px;"
						value="#{commonMsg.currentPositionLabel}每次订餐的菜单都在这了"></h:outputLabel>
				</p:toolbarGroup>
				<p:toolbarGroup align="right">
					<p:separator />
					<sec:ifAnyGranted roles="6">
						<p:button value="加个新的食堂菜单"
							outcome="/admin/order/cookbookEdit"></p:button>
					</sec:ifAnyGranted>
				</p:toolbarGroup>
			</p:toolbar>
			<h:form id="form">


				<p:dataTable lazy="true" id="dataTable"
					value="#{cookbookList.lazyModel}" var="cookbook" paginator="true"
					paginatorPosition="bottom" rows="15"
					currentPageReportTemplate="#{commonMsg.pageReportTemplate}"
					paginatorTemplate="#{commonMsg.paginatorTemplate}"
					sortBy="cookbook.id" sortOrder="descending"
					rowsPerPageTemplate="15,50,100"
					emptyMessage="#{commonMsg.noResultMsg}">
					<p:column headerText="编号"  style="text-align:center;">
						<h:outputText value="#{cookbook.id}"></h:outputText>
					</p:column>
					<p:column headerText="日期区间" style="text-align:center;">
						<h:outputText value="#{cookbook.dateBetween}"></h:outputText>
					</p:column>
					
					<p:column style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="菜单里都有啥"></h:outputText>
						</f:facet>
						<p:commandButton type="button" id="showCookbookButton" value="菜单里都有啥">
							<p:ajax listener="#{cookbookList.setCookbook(cookbook)}"
								update=":form:cookbookDialog" oncomplete="cookbookDialog.show()"
								event="click"></p:ajax>
						</p:commandButton>
					</p:column>
					
					
					<p:column style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="操作"></h:outputText>
						</f:facet>
						<sec:ifNotGranted roles="6">
						<ui:fragment rendered="#{cookbook.status == 2}">
						<h:button value="我要订这个～～"
							outcome="/admin/order/userOrderAdd?cookbook_id=#{cookbook.id}"></h:button> 
							
						</ui:fragment>
						
						<ui:fragment rendered="#{cookbook.status == 1}">
							<p:button value="没开始呢" disabled="true"></p:button> 
						</ui:fragment>
						<ui:fragment rendered="#{cookbook.status == 3}">
							<p:button value="这期订餐结束了" disabled="true"></p:button> 
						</ui:fragment>
						</sec:ifNotGranted>
							&#160;&#160;
						<sec:ifAnyGranted roles="6">
											
							
						<h:link value="#{commonMsg.editLabel}"
							outcome="/admin/order/cookbookEdit?id=#{cookbook.id}" data-type="info"></h:link> |
                    	<p:commandLink value="删除" update="@form" onstart="return confirm('删菜单？？？别乱删！！！')" 
							action="#{cookbookHome.delete(cookbook.id)}"></p:commandLink> |
                    	<p:commandLink value="通知订餐" onstart="return confirm('瞅瞅菜对不对，对了再发')" rendered="#{cookbook.status == 1}"
							action="#{cookbookHome.sendOrderNotice(cookbook.id)}"></p:commandLink>
                    	<p:commandLink value="快到时间了通知" onstart="return confirm('提醒大伙快结束了')" rendered="#{cookbook.status == 2}"
							action="#{cookbookHome.sendOrderCompleteNotice(cookbook.id)}"></p:commandLink>
						</sec:ifAnyGranted>
					</p:column>
					
				</p:dataTable>
				
				
				<p:dialog id="cookbookDialog" header="菜单单"
					widgetVar="cookbookDialog" modal="true">

					
					<p:dataTable lazy="true" id="dataTable2"
						value="#{cookbookList.dayFoods}" var="f" paginator="true"
						paginatorPosition="bottom" rows="15"
						currentPageReportTemplate="#{commonMsg.pageReportTemplate}"
						paginatorTemplate="#{commonMsg.paginatorTemplate}"
						emptyMessage="#{commonMsg.noResultMsg}">
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="菜单编号"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.cookbook.id}"></h:outputText>

						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="编号"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.id}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="日期"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.date}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="星期几"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.weekday}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="第一个菜"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.food1.name}"></h:outputText>

						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="第二个菜"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.food2.name}"></h:outputText>

						</p:column>
						

					</p:dataTable>
				</p:dialog>
				
				
				<p:dialog id="cookbookEditDialog" header="菜单单"
					widgetVar="cookbookEditDialog" modal="true">
<!-- 					<ui:include src="cookbookEdit.xhtml"></ui:include> -->
					<p:dataTable lazy="true" id="dataTable3"
						value="#{cookbookList.dayFoods}" var="f" paginator="true"
						paginatorPosition="bottom" rows="15"
						currentPageReportTemplate="#{commonMsg.pageReportTemplate}"
						paginatorTemplate="#{commonMsg.paginatorTemplate}"
						emptyMessage="#{commonMsg.noResultMsg}">
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="菜单编号"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.cookbook.id}"></h:outputText>

						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="编号"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.id}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="日期"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.date}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="星期几"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.weekday}"></h:outputText>

						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="第一个菜"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.food1.name}"></h:outputText>

						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="第二个菜"></h:outputText>
							</f:facet>
							<h:outputText value="#{f.food2.name}"></h:outputText>

						</p:column>
						

					</p:dataTable>
				</p:dialog>
				
			</h:form>
		</div>
	</ui:define>
</ui:composition>
